﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using Gem_Tools.Planning;
using Gem_Tools.Category;
using Gem_Tools.Settings;
using Gem_Tools_Utility;
using GE_Management_Tool;


namespace Gem_Tools
{
    public partial class frmMain : frmBase
    {
        public frmMain()
        {
            InitializeComponent();
            this.TopLevel = true;
            this.IsMdiContainer = true;
            this.WindowState = FormWindowState.Maximized;
            CCommon_Function.Format_All(this);

        }

        private void btnPlanning_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                frmA001_Planning_Main v_frm = new frmA001_Planning_Main();
                Load_Child_Form(v_frm);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void btnCategory_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                CConfig.g_intGem_Tools_Current_Width = this.Width;
                frmA002_Category_Main v_frm = new frmA002_Category_Main();
                Load_Child_Form(v_frm);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void btnSetting_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                frmA003_Settings_Main v_frm = new frmA003_Settings_Main();
                Load_Child_Form(v_frm);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        /// <summary>
        /// Thêm 1 child form mới.
        /// Không cho tạo 1 khi Form đó đã được gọi.
        /// </summary>
        /// <param name="pForm"></param>
        private void Load_Child_Form(Form pForm)
        {
            bool is_Exist = false;
            foreach (Form v_frm in this.MdiChildren)
            {
                if (pForm.Name == v_frm.Name)
                {
                    is_Exist = true;
                    v_frm.Focus();
                    break;
                }
            }
            if (is_Exist == false)
            {
                pForm.MdiParent = this;
                pForm.Show();
            }
        }

        private void frmMain_ResizeEnd(object sender, EventArgs e)
        {
            try
            {
                CConfig.g_intGem_Tools_Current_Width = this.Width;
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void frmMain_Shown(object sender, EventArgs e)
        {
            try
            {
                this.Visible = false;
                frmLogin v_frm = new frmLogin();
                v_frm.ShowDialog();
                if ((CSession.Active_Staff.Regency_ID != CUtility.Convert_To_Int32(EStaff_Type.Producer)) && (CSession.Active_Staff.Regency_ID != CUtility.Convert_To_Int32(EStaff_Type.Admin)))
                {
                    btnCategory.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
                    btnSetting.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
                    btnProfileManager.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
                }
                btnPlanning_ItemClick(null, null);
                this.Text = this.Text + " - " + CSession.Active_Staff.Full_Name;
                this.Visible = true;
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void btnLogout_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                Application.Restart();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            show_balloon("Welcome !");
        }

        internal void show_balloon(string v_ptr)
        {
            notifyIcon1.Text = "Gem Tools";
            notifyIcon1.Visible = true;
            notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
            notifyIcon1.BalloonTipText = v_ptr;
            notifyIcon1.BalloonTipTitle = "Warning";
            notifyIcon1.ShowBalloonTip(1000);
        }
        
    }
}